From 43d644db353209117a36dac33006e6d2dbc76224 Mon Sep 17 00:00:00 2001 From: Nicholas Smith Date: Mon, 14 Dec 2020 11:39:09 +1000 Subject: [PATCH] luci-app-watchcat: add support for new features and convert to JavaScript Signed-off-by: Nicholas Smith (cherry picked from commit d5c763ee1dc3f90ae3f493400895440f4082c4b4) Signed-off-by: Florian Eckert Remove po file changes. Does not apply clean. To many changes. --- applications/luci-app-watchcat/Makefile | 6 +- .../luci-static/resources/view/watchcat.js | 101 ++++++++++++++++++ .../luasrc/model/cbi/watchcat/watchcat.lua | 53 --------- .../share/luci/menu.d/luci-app-watchcat.json | 8 +- .../share/rpcd/acl.d/luci-app-watchcat.json | 9 +- 5 files changed, 111 insertions(+), 66 deletions(-) create mode 100644 applications/luci-app-watchcat/htdocs/luci-static/resources/view/watchcat.js delete mode 100644 applications/luci-app-watchcat/luasrc/model/cbi/watchcat/watchcat.lua diff --git a/applications/luci-app-watchcat/Makefile b/applications/luci-app-watchcat/Makefile index 58e12ecbf5..c3c7aada9d 100644 --- a/applications/luci-app-watchcat/Makefile +++ b/applications/luci-app-watchcat/Makefile @@ -1,13 +1,9 @@ -# -# Copyright (C) 2008-2014 The LuCI Team -# # This is free software, licensed under the Apache License, Version 2.0 . -# include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for Watchcat -LUCI_DEPENDS:=+luci-compat +watchcat +LUCI_DEPENDS:=+watchcat include ../../luci.mk diff --git a/applications/luci-app-watchcat/htdocs/luci-static/resources/view/watchcat.js b/applications/luci-app-watchcat/htdocs/luci-static/resources/view/watchcat.js new file mode 100644 index 0000000000..835536a300 --- /dev/null +++ b/applications/luci-app-watchcat/htdocs/luci-static/resources/view/watchcat.js @@ -0,0 +1,101 @@ +'use strict'; +'require view'; +'require form'; +'require tools.widgets as widgets'; + +return view.extend({ + render: function () { + var m, s, o; + + m = new form.Map('watchcat', + _('Watchcat'), + _("Here you can set up several checks and actions to take in the event that a host becomes unreachable. \ + Click the Add button at the bottom to set up more than one action.")); + + s = m.section(form.TypedSection, 'watchcat', _('Watchcat'), _('These rules will govern how this device reacts to network events.')); + s.anonymous = true; + s.addremove = true; + + s.tab('general', _('General Settings')); + + o = s.taboption('general', form.ListValue, 'mode', + _('Mode'), + _("Ping Reboot: Reboot this device if a ping to a specified host fails for a specified duration of time.
\ + Periodic Reboot: Reboot this device after a specified interval of time.
\ + Restart Interface: Restart a network interface if a ping to a specified host fails for a specified duration of time.")); + o.value('ping_reboot', _('Ping Reboot')); + o.value('periodic_reboot', _('Periodic Reboot')); + o.value('restart_iface', _('Restart Interface')); + + o = s.taboption('general', form.Value, 'period', + _('Period'), + _("In Periodic Reboot mode, it defines how often to reboot.
\ + In Ping Reboot mode, it defines the longest period of \ + time without a reply from the Host To Check before a reboot is engaged.
\ + In Network Restart mode, it defines the longest period of \ + time without a reply from the Host to Check before the interface is restarted. \ +

The default unit is seconds, without a suffix, but you can use the \ + suffix m for minutes, h for hours or d \ + for days.

Examples:
  • 10 seconds would be: 10 or 10s
  • 5 minutes would be: 5m
  • \ + 1 hour would be: 1h
  • 1 week would be: 7d
    • ")); + o.default = '6h'; + + o = s.taboption('general', form.Value, 'pinghosts', _('Host To Check'), _(`IPv4 address or hostname to ping.`)); + o.datatype = 'host(1)'; + o.default = '8.8.8.8'; + o.depends({ mode: "ping_reboot" }); + o.depends({ mode: "restart_iface" }); + + o = s.taboption('general', form.Value, 'pingperiod', + _('Check Interval'), + _("How often to ping the host specified above. \ +

      The default unit is seconds, without a suffix, but you can use the suffix m for minutes, h for hours or d for days.

      \ + Examples:
      • 10 seconds would be: 10 or 10s
      • 5 minutes would be: 5m
      • 1 hour would be: 1h
      • 1 week would be: 7d
        • ")); + o.default = '30s'; + o.depends({ mode: "ping_reboot" }); + o.depends({ mode: "restart_iface" }); + + o = s.taboption('general', form.ListValue, 'pingsize', + _('Ping Packet Size')); + o.value('small', _('Small: 1 byte')); + o.value('windows', _('Windows: 32 bytes')); + o.value('standard', _('Standard: 56 bytes')); + o.value('big', _('Big: 248 bytes')); + o.value('huge', _('Huge: 1492 bytes')); + o.value('jumbo', _('Jumbo: 9000 bytes')); + o.default = 'standard'; + o.depends({ mode: 'ping_reboot' }); + o.depends({ mode: 'restart_iface' }); + + o = s.taboption('general', form.Value, 'forcedelay', + _('Force Reboot Delay'), + _("Applies to Ping Reboot and Periodic Reboot modes
          When rebooting the router, the service will trigger a soft reboot. \ + Entering a non-zero value here will trigger a delayed hard reboot if the soft reboot were to fail. \ + Enter the number of seconds to wait for the soft reboot to fail or use 0 to disable the forced reboot delay.")); + o.default = '1m'; + o.depends({ mode: 'ping_reboot' }); + o.depends({ mode: 'periodic_reboot' }); + + o = s.taboption('general', widgets.NetworkSelect, 'interface', + _('Interface'), + _('Interface to monitor and/or restart'), + _('Applies to Ping Reboot and Restart Interface modes
          Specify the interface to monitor and restart if a ping over it fails.')); + o.depends({ mode: 'ping_reboot' }); + o.depends({ mode: 'restart_iface' }); + + o = s.taboption('general', widgets.NetworkSelect, 'mmifacename', + _('Name of ModemManager Interface'), + _("Applies to Ping Reboot and Restart Interface modes
          If using ModemManager, \ + you can have Watchcat restart your ModemManger interface by specifying its name.")); + o.depends({ mode: 'restart_iface' }); + o.optional = true; + + o = s.taboption('general', form.Flag, 'unlockbands', + _('Unlock Modem Bands'), + _('If using ModemManager, then before restarting the interface, set the modem to be allowed to use any band.')); + o.default = '0'; + o.depends({ mode: 'restart_iface' }); + + return m.render(); + } +}); diff --git a/applications/luci-app-watchcat/luasrc/model/cbi/watchcat/watchcat.lua b/applications/luci-app-watchcat/luasrc/model/cbi/watchcat/watchcat.lua deleted file mode 100644 index f64370bfe3..0000000000 --- a/applications/luci-app-watchcat/luasrc/model/cbi/watchcat/watchcat.lua +++ /dev/null @@ -1,53 +0,0 @@ --- Copyright 2012 Christian Gagneraud --- Licensed to the public under the Apache License 2.0. - -m = Map("system", - translate("Watchcat"), - translate("Watchcat allows configuring a periodic reboot when the " .. - "Internet connection has been lost for a certain period of time." - )) - -s = m:section(TypedSection, "watchcat") -s.anonymous = true -s.addremove = true - -mode = s:option(ListValue, "mode", - translate("Operating mode")) -mode.default = "allways" -mode:value("ping", "Reboot on internet connection lost") -mode:value("allways", "Periodic reboot") - -forcedelay = s:option(Value, "forcedelay", - translate("Forced reboot delay"), - translate("When rebooting the system, the watchcat will trigger a soft reboot. " .. - "Entering a non zero value here will trigger a delayed hard reboot " .. - "if the soft reboot fails. Enter a number of seconds to enable, " .. - "use 0 to disable")) -forcedelay.datatype = "uinteger" -forcedelay.default = "0" - -period = s:option(Value, "period", - translate("Period"), - translate("In periodic mode, it defines the reboot period. " .. - "In internet mode, it defines the longest period of " .. - "time without internet access before a reboot is engaged." .. - "Default unit is seconds, you can use the " .. - "suffix 'm' for minutes, 'h' for hours or 'd' " .. - "for days")) - -pinghost = s:option(Value, "pinghosts", - translate("Ping host"), - translate("Host address to ping")) -pinghost.datatype = "host(1)" -pinghost.default = "8.8.8.8" -pinghost:depends({mode="ping"}) - -pingperiod = s:option(Value, "pingperiod", - translate("Ping period"), - translate("How often to check internet connection. " .. - "Default unit is seconds, you can you use the " .. - "suffix 'm' for minutes, 'h' for hours or 'd' " .. - "for days")) -pingperiod:depends({mode="ping"}) - -return m diff --git a/applications/luci-app-watchcat/root/usr/share/luci/menu.d/luci-app-watchcat.json b/applications/luci-app-watchcat/root/usr/share/luci/menu.d/luci-app-watchcat.json index 80f141acd6..720c00509d 100644 --- a/applications/luci-app-watchcat/root/usr/share/luci/menu.d/luci-app-watchcat.json +++ b/applications/luci-app-watchcat/root/usr/share/luci/menu.d/luci-app-watchcat.json @@ -3,13 +3,11 @@ "title": "Watchcat", "order": 90, "action": { - "type": "cbi", - "path": "watchcat/watchcat", - "post": { "cbi.submit": true } + "type": "view", + "path": "watchcat" }, "depends": { - "acl": [ "luci-app-watchcat" ], - "uci": { "system": true } + "acl": [ "luci-app-watchcat" ] } } } diff --git a/applications/luci-app-watchcat/root/usr/share/rpcd/acl.d/luci-app-watchcat.json b/applications/luci-app-watchcat/root/usr/share/rpcd/acl.d/luci-app-watchcat.json index 29de34b6d3..ef306fab12 100644 --- a/applications/luci-app-watchcat/root/usr/share/rpcd/acl.d/luci-app-watchcat.json +++ b/applications/luci-app-watchcat/root/usr/share/rpcd/acl.d/luci-app-watchcat.json @@ -1,11 +1,14 @@ { "luci-app-watchcat": { - "description": "Grant UCI access for luci-app-watchcat", + "description": "Grant access to LuCI app watchcat", "read": { - "uci": [ "system" ] + "file": { + "/usr/bin/watchcat.sh": [ "exec" ] + }, + "uci": [ "watchcat" ] }, "write": { - "uci": [ "system" ] + "uci": [ "watchcat" ] } } } -- 2.30.2